package cn.xorange.commons.file.configuration;


import cn.xorange.commons.file.entity.LocalProperties;
import cn.xorange.commons.file.entity.Properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;


/**
 * @author : yangjian
 * @date : 2022/5/7
 */
@Configuration
public class FileConfig {

    @Bean
    @ConfigurationProperties(prefix = "oss.local")
    public LocalProperties localProperties(){
        LocalProperties properties = new LocalProperties();
        properties.setName("local");
        return properties;
    }



    @Bean
    @ConfigurationProperties(prefix = "oss.qiniu")
    public Properties qiniuProperties(){
        Properties properties = new Properties();
        properties.setName("qiniu");
        return properties;
    }

    @Bean
    @ConfigurationProperties(prefix = "oss.minio")
    public Properties minioProperties(){
        Properties properties = new Properties();
        properties.setName("minio");
        return properties;
    }


    public String getOssName(String oss){
        if(Objects.isNull(oss) || oss.isEmpty()){
            if(!this.qiniuProperties().isEnable()){
                return "local";
            }else {
                return this.qiniuProperties().getName();
            }
        }else {
            return oss;
        }
    }

    public String bucketName(){
        if(this.qiniuProperties().isEnable()){
            return this.qiniuProperties().getBucketName();
        } else if(this.minioProperties().isEnable()){
            return this.minioProperties().getBucketName();
        }else {
            return this.localProperties().getBucketName();
        }
    }






}
